home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / mutt / me2s_pl7.zoo / mu_edit2 / util / catstrs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-05  |  1.7 KB  |  90 lines

  1. static char rcsid[] = "$Id: catstrs.c,v 1.1 1992/09/06 19:31:32 mike Exp $";
  2.  
  3. /* $Log: catstrs.c,v $
  4.  * Revision 1.1  1992/09/06  19:31:32  mike
  5.  * Initial revision
  6.  *
  7.  */
  8.  
  9. /* 
  10.  * Author:
  11.  *   Lloyd Zusman        UUCP:   ...!ames!fxgrp!ljz
  12.  *   Master Byte Software    Internet:   ljz%fx.com@ames.arc.nasa.gov
  13.  *   Los Gatos, California    or try:   fxgrp!ljz@ames.arc.nasa.gov
  14.  *   "We take things well in hand."
  15.  * 
  16.  * Public Domain
  17.  * C Durland 3/92 added stdarg support
  18.  */
  19.  
  20. #ifdef __STDC__
  21.  
  22. #include <stdarg.h>
  23. #define VA_START va_start
  24.  
  25. #else    /* __STDC__ */
  26.  
  27. #include <varargs.h>
  28. #define VA_START(a,b) va_start(a)
  29.  
  30. #endif
  31.  
  32. /*
  33.  * catstrs(result, string1, string2, ..., NULL)
  34.  *
  35.  * Concatenate string1, string2, ... together into the result,
  36.  *   which must be big enough to hold all of them plus a trailing
  37.  *   '\0'.  Returns the address of the result.
  38.  *
  39.  *   Example:
  40.  *    char result[100];
  41.  *    (void)catstrs(result, "This", " ", "is a ", "test", (char *)NULL);
  42.  *    result now contains "This is a test".
  43.  */
  44. #if __STDC__
  45. char *catstrs(char *result, ...)
  46. #else
  47. char *catstrs(result, va_alist) char *result; va_dcl
  48. #endif
  49. {
  50.   va_list ap;        /* argument list pointer */
  51.   char *cp, *sp;
  52.  
  53.   VA_START(ap,result);
  54.  
  55.   sp = result;
  56.  
  57.   /*
  58.    * Loop through all the arguments, concatenating each one to the
  59.    *   result string.
  60.    */
  61.   for (cp = va_arg(ap, char *); cp; cp = va_arg(ap, char*))
  62.       while (*cp != '\0') *sp++ = *cp++;
  63.   *sp = '\0';        /* we need a trailing '\0' */
  64.  
  65.   va_end(ap);
  66.  
  67.   return result;
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. /* ****************  TEST ********************* */
  78. #ifdef TEST
  79.  
  80. main()
  81. {
  82.   char result[100];
  83.  
  84.   (void)catstrs(result, "This", " ", "is a ", "test", (char *)0);
  85.  
  86.   puts(result);
  87. }
  88.  
  89. #endif
  90.